import { Column, CreateDateColumn, Entity, JoinTable, ManyToMany, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm";
import { Role } from "./role.entity";
import { Exclude, Transform } from "class-transformer";

@Entity()
export class User {

    @PrimaryGeneratedColumn()
    id: number;

    @Column({
        length: 50,
        comment: '用户名'
    })
    // @Transform(({value}) => '用户名：' + value)
    username: string;

    
    @Column({
        length:50,
        comment: '密码',
        // select: false, // 设置接口是否返回
    })
    @Exclude()
    password: string;

    @CreateDateColumn({
        comment: '创建时间'
    })
    createTime: Date;

   
    @UpdateDateColumn({
        comment: '更新时间'
    })
    
    updateTime: Date;

    @Column({
        type: 'varchar',
        length: 255,
        comment: 'token',
        default: null
    })
    
    token: string;

    @ManyToMany(() => Role)
    @JoinTable({
        name: 'user_role_relation'
    })
    roles: Role[] 

}
